/******************************Copyright(C) Nubo*******************************
File name  : fifo.h
Description: fifo source code
Platform   : MDK V5.23.0.0
Version    : V1.0
Author     : 
Create Time: 2018-1-3
Modify     : 
Modify Time: 
******************************************************************************/

#ifndef __CN_FIFO_H
#define __CN_FIFO_H
#include "stdint.h"

/***********************************宏定义************************************/
#define TRUE                      		(1)
#define FALSE                     		(0)

/*容错宏*/
#define ERRR(conf, ret)      do              \
                            {                \
                                if (conf)    \
                                {            \
                                    ret;     \
                                }            \
                            } while(0) 
                            
#define MIN_SIZE(a, b)           ((a) > (b) ? (b) : (a))

/*******************************定义数据结构**********************************/
struct fifo_data
{
    uint8_t   *data;             //数据指针
    uint32_t   size;             //数据大小
    uint32_t   front;            //出队
    uint32_t   rear;             //入队
};

/*********************************函数声明*************************************/
uint8_t fifo_Init(struct fifo_data *head, uint8_t *buf, uint32_t len); //队列初始化
void fifo_Rst(struct fifo_data *head);                        //清空队列
uint32_t fifo_validSize(struct fifo_data *head);     //数据可用空间大小
uint8_t fifo_empty(struct fifo_data *head);        //队空判断
uint8_t fifo_puts(struct fifo_data *head, uint8_t *data, uint32_t len);
uint8_t fifo_gets(struct fifo_data *head, uint8_t *data, uint32_t len);
uint8_t fifo_putc(struct fifo_data *head, uint8_t data);
uint8_t fifo_getc(struct fifo_data *head, uint8_t *data);
uint32_t fifo_find(struct fifo_data *head, const uint8_t *data, uint32_t len);
uint8_t fifo_cmp(const struct fifo_data *fifo, uint32_t seat, const uint8_t *cmp, uint32_t cmpsize);

                            
#endif 

